/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.User;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import session.manager.UserManagerBeanLocal;

/**
 *
 * @author antonio
 */
@Stateful
public class AccountSessionBean implements AccountSessionBeanLocal {
    
    private static final Logger log = Logger.getLogger(GameSessionBean.class.getName());
    
    private User user;
   
    @EJB
    private UserManagerBeanLocal userManager;
    
    @Override
    public void initUser(String username) {
        this.user = this.userManager.find(username);
    }
    
    @Override
    public User getUser() {        
        return this.user;
    }
    
    @Override
    public void setUser(User user) {
        this.user = user;
    }
    
    @Remove
    @Override
    public void remove() {
        log.log(Level.INFO, "Logged out of: {0}", this.user.getUsername());
    }
    
    @Override
    public void changePassword(String password) {
        this.userManager.changePassword(this.user.getUsername(), password);
    }
    
    @Override
    public void changeEmail(String email) {
        this.userManager.changeEmail(this.user.getUsername(), email);
    }
    
    @Override
    public void deleteAccount() {
        this.userManager.deleteUser(this.user.getUsername());
    }
            
}
